import { queryDictAllList, queryRectificationRangeList } from '@/api/system';
import { getUserPermission, getPermissionTree } from '@/api/systemManage';
import { setStorage } from '@/config/utils';
import config from '@/config/staticData'
import Router from 'vue-router'

export default {
    // 获取系统参数
    GET_SYSTEM: (context, data) => {
        queryDictAllList().then(res => {
            context.systemInfo = res;
            setStorage('systemInfo', res);
            if (res && res.length) {
                // 获取五横五纵的参数
                let xAxis = [];
                let yAxis = [];
                if (res[0].code === config.xtWH) {
                    xAxis = [...res[0].dictValDTOList];
                }
                if (res[1].code === config.xtWZ) {
                    yAxis = [...res[1].dictValDTOList];
                }
                const twoChains = {
                    xAxis: xAxis,
                    yAxis: yAxis
                };
                sessionStorage.setItem('twoChains', JSON.stringify(twoChains));
                context.twoChains = twoChains

                // 获取文件类别
                if (res[2].code === config.fileCategory) {
                    sessionStorage.setItem('chainType', JSON.stringify(res[2].dictValDTOList))
                }
            }
        }).catch()
    },
    // 查询所有适用范围menuList
    GET_RECTIFICATION_RANGE (context, data) {
        queryRectificationRangeList().then(res => {
            sessionStorage.setItem('rangeList', JSON.stringify(res))
        }).catch()
    },
    // 当前登录用户菜单权限
    GET_USER_PERMISSION (context, data) {
        context.menuList = data
        // getUserPermission().then(res => {
        //     context.menuList = res;
        //     sessionStorage.setItem('menuList', JSON.stringify(res));
        // }).catch()
    },
    // 设置当前菜单
    SET_ACTIVE_INDEX (context, data) {
        context.activeIndex = data
        sessionStorage.setItem('activeIndex', data)
    },
    // 设置左侧
    SET_TREE_MENU (context, data) {
        context.treeMenu = data
    },
    SET_REPORTINDEX (context, data) {
        context.reportIndex = data
    },
    // 清空 vuex 中的数据
    RESET_STATE: (state) => {
        Object.assign(state, getDefaultState())
    }
}
